package com.xx.pmis.web.util;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;

import com.xx.pmis.model.Account;
import com.xx.pmis.services.AccountService;



/**
 * @class 计算流水账余额 <br>
 * 
 * @editor 石星星 @Date 2011-9-27 下午02:23:15 <br>
 * @version jdk_1.5.0
 */
public class CalculateBalance extends PMISBaseUtil {
	private static final Log log = LogFactory.getLog(CalculateBalance.class);

	AccountService accountService = getPMISServices().getAccountService();

	public double calculateAccountBalance() {

		double balance = 0.00; // 计算余额
		// 暂且用这种笨方法计算余额，存在不准确风险
		List<?> accountList = null;
		try {
			accountList = accountService.getAllAccountByCondition(" order by postDate desc");
		} catch (Exception e) {
			log.info("查询所有日常流水账异常！" + e.toString());
		}
		if (accountList.size() == 0) {
			balance = 0.00;
			log.info("余额：" + balance + "元。");
		} else {
			Account accountBalance = (Account) accountList.get(0);
			log.info("描述：" + accountBalance.getAccountDesc() + "，余额："
					+ accountBalance.getBalance() + "元。");
			balance = Double.parseDouble(accountBalance.getBalance());
		}
		log.info("记账前余额：" + balance + "元。");

		return balance;
	}
	
	@Test 
	public void testCalculateAccountBalance() {
		double balance = calculateAccountBalance();
		System.out.println("**************************" + balance);
	
		
	}
	@Test 
	public void testParseDouble() throws Exception {
		String s = "";
		double balance = Double.parseDouble(s);
		System.out.println("**************************" + balance);
		
	}

}
